﻿using PescarShop_1.Models;
using SimpleMembership.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PescarShop_1.Controllers
{
 
    public class HomeController : Controller
    {

        private ShopContext db = new ShopContext();

        public ActionResult Index(string term)
        {

           if (term == null || term == "")
           {
               ViewBag.Message = "Bienvenidos";
               ViewBag.Saludo = "Hola Mundo";

               var lista = db.productos.ToList();
               return View(lista);
           }
           else
           {
               var resultado = from p in db.productos
                               where p.Nombre.Contains(term)
                               || p.Descripcion.Contains(term)
                               || p.Marca.Nombre.Contains(term)
                               || p.Descripcion.Contains(term)
                               select p;
               return View(resultado.ToList());
           }
        }



        public ActionResult Administracion()
        {             
            return View();
        }


        public ActionResult Productos(int id)
        {

            Producto Product = db.productos.Find(id);
            return View(model: Product);
        }

        
           

    }
}
